package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysEducationMapper;
import com.ruoyi.system.domain.SysEducation;
import com.ruoyi.system.service.ISysEducationService;

/**
 * 学历设置Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-25
 */
@Service
public class SysEducationServiceImpl implements ISysEducationService 
{
    @Autowired
    private SysEducationMapper sysEducationMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询学历设置
     * 
     * @param id 学历设置主键
     * @return 学历设置
     */
    @Override
    public SysEducation selectSysEducationById(Long id)
    {
        return sysEducationMapper.selectSysEducationById(id);
    }

    /**
     * 查询学历设置列表
     * 
     * @param sysEducation 学历设置
     * @return 学历设置
     */
    @Override
    public List<SysEducation> selectSysEducationList(SysEducation sysEducation)
    {
        return sysEducationMapper.selectSysEducationList(sysEducation);
    }

    /**
     * 新增学历设置
     * 
     * @param sysEducation 学历设置
     * @return 结果
     */
    @Override
    public int insertSysEducation(SysEducation sysEducation)
    {
        return sysEducationMapper.insertSysEducation(sysEducation);
    }

    /**
     * 修改学历设置
     * 
     * @param sysEducation 学历设置
     * @return 结果
     */
    @Override
    public int updateSysEducation(SysEducation sysEducation)
    {
        return sysEducationMapper.updateSysEducation(sysEducation);
    }

    /**
     * 批量删除学历设置
     * 
     * @param ids 需要删除的学历设置主键
     * @return 结果
     */
    @Override
    public int deleteSysEducationByIds(Long[] ids)
    {
        int count = sysUserMapper.selectUserByEducationId(ids);
        if(count > 0){
            throw new GlobalException("学历已被用户所使用，无法直接删除");
        }
        return sysEducationMapper.deleteSysEducationByIds(ids);
    }

    /**
     * 删除学历设置信息
     * 
     * @param id 学历设置主键
     * @return 结果
     */
    @Override
    public int deleteSysEducationById(Long id)
    {
        return sysEducationMapper.deleteSysEducationById(id);
    }
}
